package com.fanhang.samples.thread;

import java.util.Date;

public class ThreadOrder {

	public static void main(String[] args) {
		final Thread t1 = new Thread(new Runnable() {

			@Override
			public void run() {
				System.out.println("t1 " + new Date());
				try {
					Thread.sleep(5000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				System.out.println("t1 " + new Date());
			}
		});
		
		final Thread t2 = new Thread(new Runnable() {

			@Override
			public void run() {
				System.out.println("t2 " + new Date());
				try {
					// 引用t1线程，等待t1线程执行完
					t1.join();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				System.out.println("t2 " + new Date());
			}
		});
		final Thread t3 = new Thread(new Runnable() {

			@Override
			public void run() {
				System.out.println("t3 " + new Date());
				try {
					// 引用t2线程，等待t2线程执行完
					t2.join();
					try {
						Thread.sleep(2000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				System.out.println("t3 " + new Date());
			}
		});
		t3.start();
		t2.start();
		t1.start();

	}

}
